#pragma once
#include"Queque.h"
void QuequeInit(Queque* pq)
{
	assert(pq);
	pq->head = NULL;
	pq->tail = NULL;
}
void QuequePush(Queque* pq,QNodeDataType x)
{
	assert(pq);
	QNode* newnode=(QNode*)malloc(sizeof(QNode));
	assert(newnode);
	newnode->data = x;
	newnode->next = NULL;
	if (pq->tail == NULL)
	{
		pq->head = pq->tail = newnode;
	}
	else
	{
		pq->tail->next = newnode;
		pq->tail = newnode;
	}
}
void QuequePrint(Queque* pq)
{
	assert(pq);
	QNode* cur = pq->head;
	while (cur)
	{
		printf("%d ", cur->data);
		cur = cur->next;
	}
}
void QuequeDestroy(Queque* pq)
{
	assert(pq);
	QNode* cur = pq->head;
	while (cur)
	{
		QNode* next = cur->next;
		free(cur);
		cur = next;
	}
	pq->head = pq->tail = NULL;
}
void QuequePop(Queque* pq)
{
	assert(pq);
	assert(pq->head);
	if (pq->head == NULL||pq->head->next==NULL)
	{
		pq->tail = NULL;
	}
	else
	{
		QNode* cur = pq->head;
		QNode* next = cur->next;
		free(cur);
		pq->head = next;
	}
}
bool QuequeEmpty(Queque* pq)
{
	assert(pq);
	return pq->head == NULL;
}
QNodeDataType QuequeFront(Queque* pq)
{
	assert(pq);
	assert(pq->head);
	return pq->head->data;
}
QNodeDataType QuequeBack(Queque* pq)
{
	assert(pq);
	assert(pq->tail);
	return pq->tail->data;
}
size_t QuequeSize(Queque* pq)
{
	assert(pq);
	size_t size = 0;
	QNode* cur = pq->head;
	while (cur)
	{
		size++;
		cur = cur->next;
	}
	return size;
}